package listerner;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.JDialog;
import javax.swing.JTextField;
import myaddressbook.ShowResult;
/**
 * 查询功能监听器
 * @author Little-Grey
 *
 */
public class SearchListerner implements ActionListener{
	JTextField Tname;
	JDialog dialog;
	public SearchListerner(JTextField Tname,JDialog dialog) {
		// TODO Auto-generated constructor stub
		this.Tname = Tname;
		this.dialog = dialog;
	}
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		FileReader file;
		try {
			file = new FileReader("D:\\AddressBook.txt");
			Scanner find=new Scanner(file);
			while(find.hasNext()){
			if(find.next().equals(Tname.getText())){
				dialog.dispose(); 
				String name = Tname.getText();
				System.out.println(Tname.getText());
				ShowResult my = new ShowResult();
				my.Lname2.setText(name);
				my.Lsex2.setText(find.next());
				my.Lbirthday2.setText(find.next()+find.next()+find.next());
				my.Lphone2.setText(find.next());
				my.Lemail2.setText(find.next());
				my.Lother2.setText(find.next());							
				}
			}
			file.close();
			find.close();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				System.out.print("未找到该人员");
				e.printStackTrace();
				}
		
	}
}
